<?php

class HelpController extends HBaseController
{
	public $layout = "//layouts/help";
	public $cur;

	public function actionIndex()
	{	
		//导航样式
		$this->cur = 'index';
		//买家帮助导航
		$viewdata['buyer_help'] = HelpCat::model()->findAll('zhc_parentid = 1');
		//卖家帮助中心
		$viewdata['seller_help'] = HelpCat::model()->findAll('zhc_parentid = 2');
		//常见问题
		$viewdata['faq'] = Help::model()->findAll(array('order'=>'zhe_hist DESC', 'limit'=>9));

		$this->render('index', $viewdata);
	}

	//分类列表页面
	public function actionList($id)
	{
		//根据ID查询到父级ID，然后再查出列表
		$viewdata['cat'] = $cat = HelpCat::model()->findByPk($id);
		$viewdata['list_name'] = HelpCat::model()->findAll('zhc_parentid = '.$cat->zhc_parentid);
		//导航样式
		$this->cur = $cat->zhc_parentid;
		//获取父级的title
		$parent = HelpCat::model()->findByPk($cat->zhc_parentid);
		$viewdata['title'] = $parent->zhc_title;
		
		$criteria=new CDbCriteria;
		$criteria->join = ' LEFT JOIN {{help_cat}} hc ON hc.zhc_id=t.zhc_id ';
		$criteria->addCondition(" (hc.zhc_id={$id} OR hc.zhc_parentid={$id} OR hc.zhc_topid={$id})");
		
		//查询分类下的文章
		$viewdata['dataProvider'] = new CActiveDataProvider('Help', array(
            'criteria'=>$criteria,
            'pagination'=>array(
                'pageSize'=>15,
                'pageVar' => 'page',
            ),
        ));
        //分类列表导航样式
		$viewdata['id'] = $id;

		$this->render('list', $viewdata);
	}
	
	//详细页面
	public function actionDetail($id)
	{
		//根据ID查询文章
		$viewdata['help'] = Help::model()->findByPk($id);
		//根据文章ID查询的分类ID再查分类ID的父级ID，然后再查出列表
		$viewdata['cat'] = HelpCat::model()->findByPk($viewdata['help']->zhc_id);
		$viewdata['list_name'] = HelpCat::model()->findAll('zhc_parentid = '.$viewdata['cat']->zhc_parentid);
		//导航样式
		$this->cur = $viewdata['cat']->zhc_parentid;
		//获取父级的title
		$parent = HelpCat::model()->findByPk($viewdata['cat']->zhc_parentid);
		$viewdata['title'] = $parent->zhc_title;
		//分类列表导航样式
		$viewdata['id'] = $viewdata['help']->zhc_id;

		$this->render('detail', $viewdata);
	}


	//搜索列表页面
	public function actionSearch($q)
	{
		//导航样式
		$this->cur = 'index';
		//查询分类下的文章
		$viewdata['dataProvider'] = new CActiveDataProvider('Help', array(
            'criteria'=>array(
		        'condition'=>'zhe_title like "%'.$q.'%"',
		    ),
            'pagination'=>array(
                'pageSize'=>15,
                'pageVar' => 'page',
            ),
        ));

		//常见问题
		$viewdata['faq'] = Help::model()->findAll(array('order'=>'zhe_hist DESC', 'limit'=>9));

		$this->render('search', $viewdata);
	}

}